package com.newsee.remote.ecommerce.commerce.jingdong.controller;


import com.newsee.remote.common.bean.JsonResult;
import com.newsee.remote.common.dto.ecommerce.jingdong.JDSearchDTO;
import com.newsee.remote.common.dto.ecommerce.jingdong.JDSearchPriceDTO;
import com.newsee.remote.common.vo.ecommerce.JDSearchPriceVO;
import com.newsee.remote.common.vo.ecommerce.JDSearchVO;
import com.newsee.remote.common.vo.ecommerce.SearchVO;
import com.newsee.remote.common.vo.ecommerce.SkuDetailVO;
import com.newsee.remote.ecommerce.commerce.jingdong.service.IJdItemPoolService;
import com.newsee.remote.ecommerce.commerce.jingdong.service.IJdTokenService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 京东前端控制器
 * </p>
 *
 * @author liangzhichen
 * @since 2019-08-09
 */
@RestController
@RequestMapping("/jingdong")
public class JdItemPoolController {

    private final IJdTokenService iJdTokenService;

    private final IJdItemPoolService iJdItemPoolService;

    public JdItemPoolController(IJdItemPoolService iJdItemPoolService, IJdTokenService iJdTokenService) {
        this.iJdItemPoolService = iJdItemPoolService;
        this.iJdTokenService = iJdTokenService;
    }

    @ApiOperation(value = "电商平台-京东商品开启同步接口")
    @GetMapping
    public JsonResult sync() {
        return iJdItemPoolService.sync();
    }

    @ApiOperation(value = "京东商品查询接口",response = SearchVO.class)
    @PostMapping("/search")
    public JsonResult search(@RequestBody JDSearchDTO jdSearchDTO) {
        return iJdItemPoolService.search(jdSearchDTO);
    }

    @ApiOperation(value = "京东商品价格查询接口",response = JDSearchPriceVO.class)
    @PostMapping("/search/price")
    public JDSearchPriceVO searchPrice(@RequestBody String sku) {
        return iJdItemPoolService.searchPrice(sku);
    }

    @ApiModelProperty(value = "获取京东token接口")
    @GetMapping("/token")
    public String token(){
        return iJdTokenService.getToken();
    }

    @ApiOperation(value = "获取京东详情接口",response = SkuDetailVO.class)
    @GetMapping("/search/skuDetail")
    public JsonResult skuDetail(@RequestParam String skuId) {
        return iJdItemPoolService.skuDetail(skuId);
    }
}
